import requests
import logging
class TestA3mallCart():
    def setup_method(self):
        print("初始化环境")

    def teardown_method(self):
        print("关闭对象")

    def test_dl(self):
        try:
            url="http://10.59.9.12:7001/api/public/login"
            data={"username":"13811033962","password":"123456"}
            r=requests.post(url=url,json=data)
            print(r.json())
            logging.info(r.json())
            TestA3mallCart.token="Bearer "+r.json()['data']['token']
        except Exception as e:
            logging.info(e)
        finally:
            print("执行结果")





        assert r.status_code==200

    def test_splb(self):
        try:
            url="http://10.59.9.12:7001/api/index/list?code=home&type=h5&page=1"
            data="{code=home&type=h5&page=1}"
            r = requests.get(url=url, json=data)
            print(r.json())
            logging.info(r.json())
        except Exception as e:
            logging.info(e)

        assert r.status_code == 200

    def test_spxq(self):
        try:
            url="http://10.59.9.12:7001/api/goods/view?id=103"
            data="{id=103}"
            r = requests.get(url=url, json=data)
            print(r.json())
            logging.info(r.json())
        except Exception as e:
            logging.info(e)

        assert r.status_code == 200

    def test_tjgwc(self):
        try:
            url="http://10.59.9.12:7001/api/cart/add"
            data={"id":103,"sku_id":"","num":1}
            headers={"auth-token":TestA3mallCart.token}
            r=requests.post(url=url,headers=headers,json=data)
            print(r.json())
            logging.info(r.json())
        except Exception as e:
            logging.info(e)

        assert r.status_code == 200

    def test_tjdd(self):
        try:
            url="http://10.59.9.12:7001/api/order/confirm?id=103&type=buy&sku_id=&num=1&shipping_type=1"
            data="{id=103&type=buy&sku_id=&num=1&shipping_type=1}"
            headers={"auth-token":TestA3mallCart.token}
            r = requests.get(url=url, json=data,headers=headers)
            print(r.json())
            logging.info(r.json())
        except Exception as e:
            logging.info(e)

        assert r.status_code == 200

    def test_zf(self):
        try:
            url="http://10.59.9.12:7001/api/order/create"
            data={"id":"103","type":"buy","address_id":891,"store_id":1,"shipping_type":1,"bonus_id":"0","payment":"balance","remarks":"","source":1,"url":"http://10.59.9.12:7001/wap/pages/cart/confirm?id=103&sku_id=&num=1&type=buy","sku_id":"","num":"1"}
            headers = {"auth-token": TestA3mallCart.token}
            r = requests.post(url=url, json=data, headers=headers)
            print(r.json())
            logging.info(r.json())
        except Exception as e:
            logging.info(e)

        assert r.status_code == 200

    def test_ckdd(self):
        try:
            url="http://10.59.9.12:7001/api/order/detail"
            data={"id":"490668"}
            headers = {"auth-token": TestA3mallCart.token}
            r = requests.post(url=url, json=data, headers=headers)
            print(r.json())
            logging.info(r.json())
        except Exception as e:
            logging.info(e)

        assert r.status_code == 200






